/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2013-2014 sagyf Yang. The Four Group.
 */

package app.models.sys;

import com.github.sog.annotation.TableBind;
import com.github.sog.plugin.sqlinxml.SqlKit;
import com.jfinal.plugin.activerecord.Model;

/**
 * <p>
 * .
 * </p>
 *
 * @author sagyf yang
 * @version 1.0 2014-05-11 16:43
 * @since JDK 1.6
 */
@TableBind(tableName = "ols_system_sn")
public class Sn extends Model<Sn> {
    /**
     * The public dao.
     */
    public static final Sn dao = new Sn();

    private static final String MASK_MEMBER = "member";

    private static final long serialVersionUID = -5313733022954161849L;

    public String member() {
        Sn sn = findFirst(SqlKit.sql("systemsn.findByMask"), MASK_MEMBER);
        final long current_sn = sn.getNumber("sn").longValue();
        final String sn_no = String.format(sn.getStr("format"), current_sn);
        sn.set("sn", current_sn + 1);
        sn.update();
        // 1 表示临时会员
        return "1" + sn_no;
    }
}